package cn.fboost.mtos.controller;

import cn.fboost.mtos.annotation.IgnoreTokenCheck;
import cn.fboost.mtos.dto.Response;
import cn.fboost.mtos.dto.request.AdminLoginRequest;
import cn.fboost.mtos.dto.request.WechatLoginRequest;
import cn.fboost.mtos.service.AuthService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 鉴权控制器，负责用户登录
 */
@RestController
@RequestMapping("auth")
public class AuthController {
    private final AuthService authService;

    public AuthController(AuthService authService) {
        this.authService = authService;
    }

    /**
     * 微信登录
     *
     * @param request {@link WechatLoginRequest}
     * @return {@link Response}
     * @see <a href="https://developers.weixin.qq.com/miniprogram/dev/api/open-api/login/wx.login.html">wx.login</a>
     */
    @IgnoreTokenCheck
    @PostMapping("login/wechat")
    public Response WechatLogin(@RequestBody @Validated WechatLoginRequest request) {
        return authService.wechatLogin(request);
    }

    /**
     * 管理员登录
     *
     * @param request {@link AdminLoginRequest
     * @return {@link Response}
     */
    @IgnoreTokenCheck
    @PostMapping("login/admin")
    public Response AdminLogin(@RequestBody @Validated AdminLoginRequest request) {
        return authService.adminLogin(request);
    }

    @GetMapping("info")
    public Response getInfo() {
        return authService.getInfo();
    }

    /**
     * 退出登录
     *
     * @return {@link Response}
     */
    @PostMapping("logout")
    public Response logout() {
        return authService.logout();
    }
}
